package cn.itcast.web.controller;



import cn.itcast.domain.system.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class BaseController {

    @Autowired
    protected HttpServletRequest request;
    @Autowired
    protected HttpServletResponse response;
    @Autowired
    protected HttpSession session;
    /**
     * 获取当前登录用户，所属的企业ID
     *  暂时模拟：1
     */
    public String getLoginCompanyId() {
        //获取当前登录用户
        Object obj = session.getAttribute("loginUser");
        //获取用户的企业信息
        if(obj != null) {
            User  user = (User) obj;
            return user.getCompanyId();
        }
        return null;
    }

    /**
     * 获取当前登录用户，所属的企业名称
     *  暂时模拟：传智播客
     */
    public String getLoginCompanyName() {
        //获取当前登录用户
        Object obj = session.getAttribute("loginUser");
        //获取用户的企业信息
        if(obj != null) {
            User  user = (User) obj;
            return user.getCompanyName();
        }
        return null;
    }
}
